<template>
    <h2>添加理财信息</h2>
    <table>
        <tr>
            <td>理财项目名称</td>
            <td><input type="text" v-model="info.F_name"></td>
        </tr>
        
        <tr>
            <td>年收益</td>
            <td><input type="text" v-model="info.F_APY"></td>
        </tr>
        <tr>
            <td>理财最低金额</td>
            <td><input type="text" v-model="info.F_MinMoney"></td>
        </tr>
        
        <tr>
            <td>风险等级</td>
            <td>
                <input type="radio" name="Flevel" v-model="info.F_level" value="0" checked>低
                <input type="radio" name="Flevel" v-model="info.F_level" value="1">中
                <input type="radio" name="Flevel" v-model="info.F_level" value="2">高
            </td>
        </tr>
        <tr>
            <td>理财利率</td>
            <td>
                <select v-model="info.I_id">
                    <option value="0">--请选择--</option>
                    <option v-for="item in bind"  :value="item.I_id">{{item.I_year}}年利率为{{item.I_Interest}}%</option>
                    
                    
                </select>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <input type="button"  @click="add" value="保存" class="btn btn-success">
                
            </td>
        </tr>
            
    </table>
</template>
<script setup lang="ts">
import { ref,onMounted } from 'vue';
import { useRouter } from 'vue-router';
import axios from 'axios';

const router = useRouter();

const bind = ref([{
    I_id:0,
    I_year:0,
    I_Interest:0,
}])

const info = ref({
    F_name:'',
    F_APY:'',
    F_MinMoney:'',
    F_number:'',
    F_level:0,
    I_id:0,
})

onMounted(() => {
    LoadInterest();
})

const LoadInterest = () => {
    axios
    .get('http://localhost:58004/api/Finan/ShowInterestInfo')
    .then(res => {
        console.log(res.data);
        bind.value = res.data; 
    })
}


const add = () => {
    axios.post('http://localhost:58004/api/Finan/AddInanInfo',info.value)
    .then(res => {
        if(res.data>0){
            alert('添加成功');
            router.push('/ShowFinan');
        }
        else if(res.data==-1){
            alert('理财名称已存在');
            
        }
        else
        {
            alert('添加失败');
        }
    })
    .catch(err => {
        console.log(err);
    })
}
</script>